/*
 * @Author: xiaoyan
 * @Date: 2022-01-20 13:57:01
 * @LastEditors: xiaoyan
 * @LastEditTime: 2022-02-10 15:10:45
 * @Description: 字典数据
 * @FilePath: \user_auth_front\src\store\modules\dictionary.ts
 */
const SET_ORGANIZATIONLISTS= "set_organizationLists";
const SET_ROLELISTS = "set_roleLists";
const SET_APPLICATIONLISTS = "set_applicationLists";

interface MyState{
    organizationLists:Array<any>;
    roleLists:Array<any>;
    applicationLists:Array<any>;
}

const defaultState:MyState = {
    organizationLists:[],
    roleLists:[],
    applicationLists:[],
};

type TSetOrganizationLists = {
    type:String;
    payload:Array<any>;
}
type TSetRoleLists = {
    type:String;
    payload:Array<any>;
}

type TSetApplicationLists = {
    type:String;
    payload:Array<any>;
}

export type Actions = TSetOrganizationLists | TSetRoleLists | TSetApplicationLists;

export default (state:MyState = defaultState,action:Actions)=>{
    switch(action.type){
        case SET_ORGANIZATIONLISTS:
            return Object.assign({},state,{
                organizationLists:action.payload
            });
        case SET_ROLELISTS:
            return Object.assign({},state,{
                roleLists:action.payload
            });
        case SET_APPLICATIONLISTS:
            return Object.assign({},state,{
                applicationLists:action.payload
            });
        default:
            return state;
    }
}

export const setOrganizationLists = (val:Array<any>)=>({
    type:SET_ORGANIZATIONLISTS,
    payload:val,
});
export const setRoleLists = (val:Array<any>)=>({
    type:SET_ROLELISTS,
    payload:val,
});
export const setApplicationLists = (val:Array<any>)=>({
    type:SET_APPLICATIONLISTS,
    payload:val,
});